package xyz.hujf.base.threadLocal;

/**
 * @author Hujf
 * @title: ThreadLocalTest
 * @date 2021-04-239:40
 * @description: 提供线程本地变量
 *
 * 利用一个 ThreadLocalMap 定制存储线程数据
 */
public class ThreadLocalTest {

    static ThreadLocal<String> local = new ThreadLocal<String>();

    static void print(String str){
        System.out.println(str+":"+local.get());
        local.remove();
    }

    public static void main(String[] args) {
        Thread th1 = new Thread(()->{
           local.set("线程1");
            print("线程1");
        });

        Thread th2 = new Thread(()->{
           local.set("线程2");
            print("线程2");
        });
    }
}
